package com.zzyl.nursing.job;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.zzyl.nursing.domain.Contract;
import com.zzyl.nursing.domain.Elder;
import com.zzyl.nursing.mapper.CheckInMapper;
import com.zzyl.nursing.mapper.ContractMapper;
import com.zzyl.nursing.mapper.ElderMapper;
import com.zzyl.nursing.service.IContractService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@Component("UpdateContractStatusJob")
public class UpdateContractStatusJob {
    @Autowired
    private ContractMapper contractMapper;
    @Autowired
    private ElderMapper elderMapper;
@Autowired
    private IContractService iContractService;

    public void updateStatus() {
        /*List<Contract> contracts = contractMapper.selectAll();

            for (Contract contract : contracts) {
                if (contract.getSignDate().isBefore(LocalDateTime.now())){
                    contract.setStatus(1);
                }else if (contract.getSignDate().isAfter(LocalDateTime.now())){
                    contract.setStatus(0);
                }else if (contract.getSignDate().isAfter(contract.getEndDate())){
                    contract.setStatus(2);
                }

                contractMapper.updateContract(contract);
            }*/

        //未生效到生效
        LambdaUpdateWrapper<Contract> updateWrapper=new LambdaUpdateWrapper<>();
        updateWrapper.set(Contract::getStatus,1);
        updateWrapper.eq(Contract::getStatus,0);
        updateWrapper.lt(Contract::getStartDate,LocalDateTime.now());
        updateWrapper.gt(Contract::getEndDate,LocalDateTime.now());
        iContractService.update(updateWrapper);
        //生效到已过期
        LambdaUpdateWrapper<Contract> updateWrapper1=new LambdaUpdateWrapper<>();
        updateWrapper1.set(Contract::getStatus,2);
        updateWrapper1.eq(Contract::getStatus,1);
        updateWrapper1.lt(Contract::getEndDate,LocalDateTime.now());
        iContractService.update(updateWrapper1);
        }


    }




